﻿using MiniCAP.Core;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MiniCAP.MySQL
{
    public static class TransactionExtensions
    {
        public static async Task<IDbTransaction> BeginMiniCapTransactionAsync(
            this IDbConnection connection,
            IMessagePublisher publisher)
        {
            var transaction = await connection.BeginTransactionAsync();

            // 将事务上下文传递给发布者  
            if (publisher is MessagePublisher impl)
            {
                impl.SetCurrentTransaction(transaction);
            }

            return transaction;
        }
    }
}
